<template>
  <div class="login_container" >
    <div class="login" id="login">
     <a href="javascript:;" class="log-close"><i class="icons close"></i></a>
    <!-- <div class="log-bg">
      <div class="log-cloud cloud1"></div>
      <div class="log-cloud cloud2"></div>
      <div class="log-cloud cloud3"></div>
      <div class="log-cloud cloud4"></div>
      <div class="log-logo">logo!</div>
      <div class="log-text">桂花糖</div>
    </div>   -->
      <div class="login_form yanzheng" > 
        <h3 style="margin:15px auto;">桂花糖</h3>
         <verified class="code" v-if="slidPicVisible" @successHandle="login()" @close="close()"></verified>
        <el-tabs v-model="activeName" @tab-click="handleClick" >
          <el-tab-pane label="登录" name="first">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="70px" >
              <el-form-item label="用户名" prop="username">
                <el-input v-model="ruleForm.username"></el-input>
              </el-form-item>
              <el-form-item  label="密码" prop="password">
                <el-input type="password" v-model="ruleForm.password" auto-complete="off"></el-input>
              </el-form-item>
              <!-- <el-form-item>
                  <router-link to="/" class="nav-link my-nav-link">忘记密码？</router-link>
              </el-form-item> -->
              <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')" v-on:keyup.13.native="submitForm('ruleForm')">登录</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="注册" name="second">
            <register @callback="callback"></register>
          </el-tab-pane>
          <el-tab-pane label="密码找回" name="three">
            <forgetpwd @callback="callback"></forgetpwd>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>
<script>
  import register from '../register/index'
  import forgetpwd from '../forgetpwd/index'
  import "../../components/captcha/index.js";
  import verified from "../../components/captcha/myindex"; //滑块验证码
  export default {
    components: {
      register,
      verified,
      forgetpwd
    },
    data() { 
      var validatePhone = (rule, value, callback) => {
        const telStr = /^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$/;
       if (value === '') {
          callback(new Error('请输入正确用户名'));
        }
        // else if (!(telStr.test(value))) { 
        //   callback(new Error('请输入正确手机号'));
        // }
        else{ 
          callback();
        }
      };
      return {
        activeName: 'first',
        slidPicVisible:false,
        ruleForm: {
          username: '',
          password: '', 
        },
        rules: {  
          password: [{
              required: true,
              message: '请输入您的密码',
              trigger: 'blur'
            },
            {
              min:6,
              max: 11,
              message: '长度在 6至11 个字符',
              trigger: 'blur'
            }
          ],
          username: [{
            required: true,
            validator: validatePhone,
            trigger: 'blur'
          }]
        },

      };
    },
    mounted() {
      //装载登录 
      this.activeName = this.$route.params.args; 

    },
    created(){
      var _this = this;
      document.onkeydown = function(e) {
        let key = window.event.keyCode;
        if (key == 13) {
          _this.submitForm('ruleForm');
        }
      };
    },
    methods: {
      //选项卡切换
      keydownlogin(e){
        console.log();
      },
      handleClick(tab, event) {},
      callback(){
         this.activeName='first'
      },
      login(){
        setTimeout(()=>{
          this.slidPicVisible = false;
          this.$store.dispatch("user/login",this.ruleForm).then(resp=>{ 
            if(resp.status==200){
                 this.$message({
                  type: 'success',
                  message: '登录成功'
                });
                this.$router.push(this.$route.query.redirect?this.$route.query.redirect:'/');
            }else{
               this.$message({
                  type: 'error',
                  message: resp.msg||'登录失败'
                });
            }
          },res=>{
            console.log(res);
          })
        },500) 
      },
      close(){
        this.slidPicVisible = false;
      },
      //重置表单
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      //提交表单
      submitForm(formName) { 
        this.$refs[formName].validate((valid) => {   
           if (valid) this.slidPicVisible = true;  
        });
      }
    }
  }
</script>
<style scoped>
 
  @import "../../components/captcha/index.css";
  .login_container {
    background: #1380D2;
    width:100%;
    height:100vh;
    padding-top:15%;
  }
  .login {
    position: relative;
    overflow: hidden;
    /* left: 50%; */
    /* margin-left: -250px; */
    /* top: 50%; */
    /* margin-top: -250px; */
    width: 98%;
    max-width:400px;
    /* min-height: 555px; */
    z-index: 10;
    /* right: 140px; */
    margin:0px auto;
    background: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: 0px 3px 16px -5px #070707;
    box-shadow: 0px 3px 16px -5px #070707
  }

  .log-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    opacity: 1;
  }

  .log-close:hover .icons {
    transform: rotate(180deg);
  }

  .log-close .icons {
    opacity: 1;
    transition: all .3s
  }

  .log-cloud {
    background-image: url("../../../static/images/login-cloud.png");
    width: 63px;
    height: 40px;
    position: absolute;
    z-index: 1
  }

  .login .cloud1 {
    top: 21px;
    left: -30px;
    transform: scale(.6);
    animation: cloud1 20s linear infinite;
  }

  .login .cloud2 {
    top: 87px;
    right: 20px;
    animation: cloud2 19s linear infinite;
  }

  .login .cloud3 {
    top: 160px;
    left: 5px;
    transform: scale(.8);
    animation: cloud3 21s linear infinite;
  }

  .login .cloud4 {
    top: 150px;
    left: -40px;
    transform: scale(.4);
    animation: cloud4 19s linear infinite;
  }

  .log-bg {
    background: url(../../../static/images/login_bg.jpg);
    width: 100%;
    height: 312px;
    overflow: hidden;
  }

  .log-logo {
    height: 80px;
    margin: 120px auto 25px;
    text-align: center;
    color: #1fcab3;
    font-weight: bold;
    font-size: 40px;
  }

  .log-text {
    color: #57d4c3;
    font-size: 13px;
    text-align: center;
    margin: 0 auto;
  }

  .log-logo,
  .log-text {
    z-index: 2
  }

  .icons {
    background: url("../../../static/images/icons.png") no-repeat;
    display: inline-block;
  }

  .close {
    height: 16px;
    width: 16px;
    background-position: -13px 0;
  }

  .login_form {
    width: 80%;
    margin: 0px auto;
    min-height: 326px;
  }

  .log-btns {
    padding: 15px 0;
    margin: 0 auto;
  }

  .log-btn {
    width: 402px;
    display: block;
    text-align: left;
    line-height: 50px;
    margin: 0 auto 15px;
    height: 50px;
    color: #fff;
    font-size: 13px;
    -webkit-border-radius: 5px;
    background-color: #3B5999;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    position: relative;
  }

  .log-btn.tw {
    background-color: #13B4E9
  }

  .log-btn.email {
    background-color: #50E3CE
  }

  .log-btn:hover,
  .log-btn:focus {
    color: #fff;
    opacity: .8;
  }

  .login_from {
    text-align: center;
    margin-top: 20px;
  }

  .log-btn .icons {
    margin-left: 30px;
    vertical-align: middle;
  }

  .log-btn .text {
    left: 95px;
    line-height: 50px;
    text-align: left;
    position: absolute;
  }

  .log-input {
    width: 370px;
    overflow: hidden;
    padding: 0 15px;
    font-size: 13px;
    border: 1px solid #EBEBEB;
    margin: 0 auto 15px;
    height: 48px;
    line-height: 48px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
  }

  .log-input.warn {
    border: 1px solid #f88787
  }

  @-webkit-keyframes cloud1 {
    0% {
      left: 200px
    }

    100% {
      left: -130px;
    }
  }

  @keyframes cloud1 {
    0% {
      left: 200px
    }

    100% {
      left: -130px;
    }
  }

  @-webkit-keyframes cloud2 {
    0% {
      left: 500px;
    }

    100% {
      left: -90px;
    }
  }

  @keyframes cloud2 {
    0% {
      left: 500px;
    }

    100% {
      left: -90px;
    }
  }

  @-webkit-keyframes cloud3 {
    0% {
      left: 620px;
    }

    100% {
      left: -70px;
    }
  }

  @keyframes cloud3 {
    0% {
      left: 620px;
    }

    100% {
      left: -70px;
    }
  }

  @-webkit-keyframes cloud4 {
    0% {
      left: 100px;
    }

    100% {
      left: -70px;
    }
  }

  @keyframes cloud4 {
    0% {
      left: 100px;
    }

    100% {
      left: -70px;
    }
  }

  .yanzheng{
    position:relative;
  }
  .code{
    position: absolute;
    background:#fff;
    top:40px;
    right:-30px;
    z-index:99999;
  }
</style>
